//封装的 存储到本地的方法

//存需要转换成json
let set = (key, value) => {
    if (key && value) {
        //把value转换成json
        try {
            let json = JSON.stringify(value)
            localStorage.setItem(key, json)
        } catch (e) {
            console.error('key和value必须传递')
        }
    }
}

//取需要转换成正常的对象
let get = (key) => {
    let res = localStorage.getItem(key)
    try {
        let result = JSON.parse(res)
        return result
    } catch (e) {
        console.log(e);
        return res
    }
} 

//移除
let rm = key => {
    localStorage.removeItem(key)
}

export default {
    get,
    set,
    rm
}

